<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>打招呼信息统计 - n8n工作流监控系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', 'PingFang SC', 'Hiragino Sans GB', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            text-align: center;
            color: white;
            margin-bottom: 30px;
        }
        
        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .back-btn {
            background: white;
            color: #667eea;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            font-size: 1em;
            font-weight: bold;
            cursor: pointer;
            margin-top: 15px;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            text-decoration: none;
            display: inline-block;
        }
        
        .back-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0,0,0,0.3);
        }
        
        .main-section {
            background: white;
            border-radius: 15px;
            padding: 40px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            text-align: center;
        }
        
        .stats-section {
            margin: 30px 0;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }
        
        .stat-card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
        }
        
        .stat-card .label {
            font-size: 0.9em;
            color: #666;
            margin-bottom: 10px;
        }
        
        .stat-card .value {
            font-size: 2em;
            font-weight: bold;
            color: #667eea;
        }
        
        .info-text {
            background: #e3f2fd;
            border-left: 4px solid #2196f3;
            padding: 15px 20px;
            margin: 20px 0;
            border-radius: 5px;
            text-align: left;
            color: #1976d2;
        }
        
        .list-section {
            margin-top: 40px;
            text-align: left;
        }
        
        .list-section h3 {
            color: #333;
            margin-bottom: 20px;
            font-size: 1.3em;
            padding-bottom: 10px;
            border-bottom: 2px solid #667eea;
        }
        
        .message-list {
            margin-top: 20px;
        }
        
        .message-item {
            background: #f8f9fa;
            border-left: 4px solid #10b981;
            padding: 15px;
            margin-bottom: 15px;
            border-radius: 5px;
        }
        
        .message-item .candidate-name {
            font-weight: bold;
            color: #667eea;
            margin-bottom: 8px;
        }
        
        .message-item .content {
            color: #666;
            line-height: 1.6;
            margin-bottom: 8px;
            word-wrap: break-word;
        }
        
        .message-item .time {
            font-size: 0.85em;
            color: #999;
        }
        
        .loading {
            text-align: center;
            padding: 50px;
            font-size: 1.5em;
            color: #666;
        }
        
        .no-data {
            text-align: center;
            padding: 50px;
            color: #999;
            font-size: 1.2em;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>👋 打招呼信息统计</h1>
            <button class="back-btn" onclick="window.location.href='index.html'">← 返回主页</button>
        </div>
        
        <div class="main-section">
            <div id="loadingMessage" class="loading">
                正在加载数据...
            </div>
            
            <div id="content" style="display: none;">
                <div class="stats-section">
                    <div class="info-text">
                        ℹ️ 打招呼信息是系统主动向候选人发送的统一消息，用于主动接触候选人。以下统计信息来自最近30天的数据。
                    </div>
                    
                    <div class="stats-grid">
                        <div class="stat-card">
                            <div class="label">总AI消息数</div>
                            <div class="value" id="totalAIMessages">-</div>
                        </div>
                        <div class="stat-card">
                            <div class="label">打招呼消息数</div>
                            <div class="value" id="greetingCount">-</div>
                        </div>
                        <div class="stat-card">
                            <div class="label">打招呼率</div>
                            <div class="value" id="greetingRate">-%</div>
                        </div>
                    </div>
                </div>
                
                <div class="list-section">
                    <h3>📋 打招呼消息列表</h3>
                    <div id="messageList" class="message-list">
                        <!-- 消息列表将在这里动态填充 -->
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        async function loadGreetingData() {
            try {
                console.log('开始加载打招呼数据...');
                const response = await fetch('static/monitor_report.json');
                if (!response.ok) throw new Error('无法加载报告文件');
                
                const data = await response.json();
                console.log('数据加载成功', data);
                
                displayGreetingData(data);
                
                document.getElementById('loadingMessage').style.display = 'none';
                document.getElementById('content').style.display = 'block';
                
            } catch (error) {
                console.error('加载打招呼数据失败:', error);
                document.getElementById('loadingMessage').textContent = '❌ 加载数据失败: ' + error.message;
            }
        }
        
        function displayGreetingData(data) {
            console.log('开始显示打招呼数据...');
            
            // 从greeting_analysis中获取数据
            const greetingAnalysis = data.greeting_analysis || {};
            const greetingCount = greetingAnalysis.greeting_count || 0;
            const totalAIMessages = greetingAnalysis.total_ai_messages || 0;
            const greetingRate = greetingAnalysis.greeting_rate || 0;
            const issues = greetingAnalysis.issues || [];
            
            console.log('打招呼统计信息:', {
                greetingCount,
                totalAIMessages,
                greetingRate,
                issuesCount: issues.length
            });
            
            // 显示统计信息
            document.getElementById('totalAIMessages').textContent = totalAIMessages;
            document.getElementById('greetingCount').textContent = greetingCount;
            document.getElementById('greetingRate').textContent = greetingRate.toFixed(2) + '%';
            
            // 显示消息列表
            const listContainer = document.getElementById('messageList');
            
            if (issues.length === 0) {
                listContainer.innerHTML = '<div class="no-data">暂无打招呼消息数据</div>';
            } else {
                listContainer.innerHTML = issues.map((issue, index) => `
                    <div class="message-item">
                        <div class="candidate-name">${index + 1}. ${issue.candidate_name}</div>
                        <div class="content">${issue.content}</div>
                        <div class="time">时间: ${issue.created_at}</div>
                    </div>
                `).join('');
            }
        }
        
        // 页面加载时执行
        window.addEventListener('DOMContentLoaded', loadGreetingData);
    </script>
</body>
</html>

